package org.jeecg.modules.user.member.controller;

import cn.hutool.core.util.RandomUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.MemberAPI;
import org.jeecg.common.api.dto.MemberDTO;
import org.jeecg.common.system.util.JwtUtil;
import org.jeecg.modules.constant.BikeConstant;
import org.jeecg.modules.param.advise.entity.BikeMemberUserAdvise;
import org.jeecg.modules.param.advise.service.IBikeMemberUserAdviseService;
import org.jeecg.modules.system.announcement.service.IBikeAnnouncementService;
import org.jeecg.modules.user.member.dto.AdviseReq;
import org.jeecg.modules.utils.BikeResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
* @Description: bike_pile
* @Author: jeecg-boot
* @Date:   2021-05-19
* @Version: V1.0
*/
@Api(tags="意见反馈")
@RestController
@RequestMapping("/app/advise")
@Slf4j
public class AdviseController  {

    @Autowired
    private MemberAPI memberAPI;
    @Autowired
    private IBikeMemberUserAdviseService adviseService;
    @Autowired
    private IBikeAnnouncementService bikeAnnouncementService;


    @ApiOperation(value = "添加意见反馈", notes = "添加意见反馈")
    @RequestMapping(value = "/addAdvise", method = RequestMethod.POST)
    public BikeResult addAdvise(@RequestBody AdviseReq adviseReq, HttpServletRequest request){
        String accessToken = request.getHeader("X-Access-Token");
        // 解密获得username，用于和数据库进行对比
        String username = JwtUtil.getUsername(accessToken);
        MemberDTO member = memberAPI.getMember(username);
        String uuid = RandomUtil.randomString(16);
        BikeMemberUserAdvise bikeMemberUserAdvise = new BikeMemberUserAdvise();
        bikeMemberUserAdvise.setId(uuid);
        bikeMemberUserAdvise.setUserId(member.getId());
        bikeMemberUserAdvise.setContent(adviseReq.getContent());
        bikeMemberUserAdvise.setFileUrlOne(adviseReq.getFileUrlOne());
        bikeMemberUserAdvise.setFileUrlTwo(adviseReq.getFileUrlTwo());
        bikeMemberUserAdvise.setFileUrlThree(adviseReq.getFileUrlThree());
        adviseService.save(bikeMemberUserAdvise);
        return BikeResult.ok("1","提交成功",null);
    }

    @ApiOperation(value = "意见反馈记录", notes = "意见反馈记录")
    @RequestMapping(value = "/getAdviseList", method = RequestMethod.GET)
    public BikeResult getAdviseList(@RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize, HttpServletRequest request){

        return adviseService.getAdviseList(pageNo,pageSize,request);
    }




}
